package com.example.myapplication;

import android.bluetooth.BluetoothAdapter;
import android.bluetooth.BluetoothDevice;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.util.Log;

public class MyReceiver extends BroadcastReceiver {

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        //开始查找设备
        if (BluetoothAdapter.ACTION_DISCOVERY_STARTED == action) {
            Log.d("mjt", "开始查找");
        } else if (BluetoothDevice.ACTION_FOUND == action) {
            //搜到蓝牙设备
            BluetoothDevice device = intent.getParcelableExtra(BluetoothDevice.EXTRA_DEVICE);

             Log.d("mjt", " 设备名：" + device.getName() + "地址：" + device.getAddress());

        } else if (BluetoothAdapter.ACTION_DISCOVERY_FINISHED == action) {
            //搜索完毕
            //     Toast.makeText(MainActivity.this, "选择要配对的蓝牙设备", Toast.LENGTH_SHORT).show();
            Log.d("mjt", "查找结束");
        }
    }
}